﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DX_SourceOutliner
{
    public static class NodeIterator
    {
        public static IEnumerable<TreeNode> Apply(IEnumerable<TreeNode> nodes, Func<TreeNode, TreeNode> functionToApply)
        {
            foreach (TreeNode node in nodes)
            {
                functionToApply(node);

                var childNodes = new List<TreeNode>();

                foreach (TreeNode n in node.Nodes)
                {
                    childNodes.Add(n);
                }

                Apply(childNodes, functionToApply);
            }

            return nodes;
        }

    }
}
